package com.springapi.controller;

import com.springapi.entity.Mailreport;
import com.springapi.service.MailreportService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 系统设置(Mailreport)表控制层
 *
 * @author makejava
 * @since 2025-01-23 11:18:13
 */
@RestController
@RequestMapping("/api/mailreport")
public class MailreportController {
    /**
     * 服务对象
     */
    @Resource
    private MailreportService mailreportService;

    //通过appid和shopid查询店铺本周入库包裹数量（根据日期分组统计）
    @GetMapping("/findmailreport1")
    public List<Mailreport> findmailreport1(@RequestParam int appid, @RequestParam int shopid) {
        System.out.println("appid:"+appid);
        System.out.println("shopid:"+shopid);
        return mailreportService.findmailreport1(appid,shopid);
    }



    /**
     * 分页查询
     *
     * @param mailreport 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Mailreport>> queryByPage(Mailreport mailreport, PageRequest pageRequest) {
        return ResponseEntity.ok(this.mailreportService.queryByPage(mailreport, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Mailreport> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.mailreportService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param mailreport 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Mailreport> add(Mailreport mailreport) {
        return ResponseEntity.ok(this.mailreportService.insert(mailreport));
    }

    /**
     * 编辑数据
     *
     * @param mailreport 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Mailreport> edit(Mailreport mailreport) {
        return ResponseEntity.ok(this.mailreportService.update(mailreport));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.mailreportService.deleteById(id));
    }

}

